import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
var _ = require('lodash')

const stateTpl = {
    uid: {
        type: Number,
        default: -1
    },
    uname: '',
    avatar: '',
    likedTalkIdList: {
        type: Array
    }
}


const store = new Vuex.Store({
    state: _.cloneDeep(stateTpl),
    mutations: {
        // 被vue tools追踪，函数操作
        resetAll (state) {
            Object.assign(state, stateTpl)
        },
        addLike(state, talk_id) {
            state.likedTalkIdList.push(talk_id)
        },
        removeLike(state, index) {
            state.likedTalkIdList.splice(index, 1)
        }
    },
    actions: {
        // 异步操作

    },
    getters: {

    }, 
    modules: {
        // 方便扩展
    }
})

export default store
